<template>
  <div class="search-container mtop" v-if="show">
    <div class="searchbar">
      <input type="text" v-model.trim="nickname" @blur.stop="blurSearch" @keypress="handleSearch" placeholder="搜索会员账号">
      <!-- <span class="btn" @click="handleSearch(true)" v-if="!nickname">搜索</span>
      <span class="btn" @click="handleSearch(false)" v-else>取消</span> -->
      <span class="btn" @click="cancelSearch" >取消</span>
    </div>
  </div>
</template>
<script>

export default {
  props: {
    show: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      nickname: ''
    }
  },
  methods: {
    handleSearch (event) {
      if (event.keyCode === 13) {
        event.preventDefault();
        // if (!this.nickname) {
        //   this.$vux.toast.text('请输入会员账号');
        // }
        this.$emit('close', this.nickname);
        // this.nickname = '';
      }
    },
    blurSearch (event) {
      if (this.nickname && !event.keyCode) {
        // this.$emit('close', this.nickname);
      }
    },
    cancelSearch () {
      this.nickname = '';
      this.$emit('close', '');
    }
  }
}
</script>
<style lang="less" scoped>
  @import '../../../assets/styles/mixins.less';
  .search-container {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: #F7F7F7;
    z-index: 100;
    .searchbar {
      position: relative;
      height: 1.08rem;
      padding: 0.2rem 0.84rem 0.2rem 0.2rem;
      background: #fff;
      box-sizing: border-box;
      &::after {
        content: '';
        display: block;
        width: 100%;
        height: 0.16rem;
        position: absolute;
        left: 0;
        bottom: -0.16rem;
        background: #f7f7f7;
      }
      input {
        display: flex;
        align-content: center;
        height: 100%;
        width: 100%;
        padding: 0.1rem 0.2rem;
        background: #F7F7F7;
        border-radius: 0.17rem;
        box-sizing: border-box;
        &::-webkit-input-placeholder {
          color: #d2d2d2;
          font-size: 0.28rem;
        }
      }
      .btn {
        display: flex;
        align-items: center;
        position: absolute;
        right: 0;
        top: 0;
        height: 100%;
        width: 0.84rem;
        padding-left: 0.1rem;
        font-size: 0.28rem;
        color: #333333;
        box-sizing: border-box;
      }
    }
  }
</style>
